
//
//  LayListView.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/18.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "LayListView.h"
#import "LayListTableViewCell.h"
#import "ReleaseAdviceViewController.h"
@implementation LayListView{
    CAShapeLayer *maskLayer;
    UIBezierPath *maskPath;
    CAShapeLayer *maskLayer3;
    UIBezierPath *maskPath3;
    
}

-(void)creatView{
    self.backgroundColor=_LightGrey;
    
    _tableView=[BaseTableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT);
    }];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    
    _headView=[UIView new];
    [_headView setFrame:CGRectMake(0, 0,_mainW ,60)];
    _headView.backgroundColor=_LightGrey;
    _tableView.tableHeaderView=_headView;
    
    
    
    _xueYuan=[UIButton new];
    [_headView addSubview:_xueYuan];
    [_xueYuan setFrame:CGRectMake(0, 5, _mainW*0.4, 50)];
    [_xueYuan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(_mainW*0.1);
        make.width.mas_equalTo(_mainW*0.4);
        make.height.mas_equalTo(50);
    }];
    
    maskPath = [UIBezierPath bezierPathWithRoundedRect:_xueYuan.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(10, 10)];
    
    maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _xueYuan.bounds;
    maskLayer.path = maskPath.CGPath;
    [_xueYuan.layer addSublayer:maskLayer];
    
    _geShou=[UIButton new];
    [_headView addSubview:_geShou];
    [_geShou setFrame:CGRectMake(0, 5, _mainW*0.4, 50)];
    [_geShou mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_xueYuan);
        make.left.mas_equalTo(_xueYuan.mas_right).mas_equalTo(0);
        make.width.mas_equalTo(_mainW*0.4);
        make.height.mas_equalTo(50);
    }];
    
    maskPath3 = [UIBezierPath bezierPathWithRoundedRect:_geShou.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    maskLayer3 = [[CAShapeLayer alloc] init];
    maskLayer3.frame = _geShou.bounds;
    maskLayer3.path = maskPath3.CGPath;
    [_geShou.layer addSublayer:maskLayer3];
    
    if ([_is_mine isEqualToString:@"0"]){
        maskLayer.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer.fillColor = _backgroundColor.CGColor;
        maskLayer.lineWidth = 1;
        maskLayer.lineJoin = kCALineJoinRound;
        maskLayer.lineCap = kCALineCapRound;
        maskLayer.path = maskPath.CGPath;
        [_xueYuan setTitle:@"我的" forState:UIControlStateNormal];
        [_xueYuan setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        maskLayer3.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer3.fillColor = [UIColor whiteColor].CGColor;
        maskLayer3.lineWidth = 1;
        maskLayer3.lineJoin = kCALineJoinRound;
        maskLayer3.lineCap = kCALineCapRound;
        maskLayer3.path = maskPath3.CGPath;
        [_geShou setTitle:@"听过的" forState:UIControlStateNormal];
        [_geShou setTitleColor:ColorWithRGB(149, 149, 149) forState:UIControlStateNormal];
    }
    else{
        maskLayer.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer.fillColor = [UIColor colorWithRed:220/255 green:220/255 blue:220/255 alpha:0.2].CGColor;
        maskLayer.lineWidth = 1;
        maskLayer.lineJoin = kCALineJoinRound;
        maskLayer.lineCap = kCALineCapRound;
        maskLayer.path = maskPath.CGPath;
        [_xueYuan setTitle:@"我的" forState:UIControlStateNormal];
        [_xueYuan setTitleColor:ColorWithRGB(149, 149, 149) forState:UIControlStateNormal];
        
        maskLayer3.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer3.fillColor = _backgroundColor.CGColor;
        maskLayer3.lineWidth = 1;
        maskLayer3.lineJoin = kCALineJoinRound;
        maskLayer3.lineCap = kCALineCapRound;
        maskLayer3.path = maskPath3.CGPath;
        [_geShou setTitle:@"听过的" forState:UIControlStateNormal];
        [_geShou setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    _xueYuan.tag=1;
    [_xueYuan addTarget:self action:@selector(selectWoDeOrList:) forControlEvents:UIControlEventTouchUpInside];
    _geShou.tag=2;
    [_geShou addTarget:self action:@selector(selectWoDeOrList:) forControlEvents:UIControlEventTouchUpInside];

    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    [_kongBai shanChu];
    
    if (_tableArr.count==0) {
        _kongBai=[kongBaiye new];
        [self addSubview:_kongBai];
        [_kongBai mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.top.mas_equalTo(NAV_HEIGHT+60);
        }];
        [_kongBai creatView];
        _kongBai.customSelectedBlock  = ^{
            [self loadData];
        };
        return 0;
    }
    
    return _tableArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LayListTableViewCell *cell=[[LayListTableViewCell alloc] init];
    cell.tableDic=_tableArr[indexPath.row];
    [cell creatView];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 210;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ReleaseAdviceViewController *law=[[ReleaseAdviceViewController alloc] init];
    law.dic=_tableArr[indexPath.row];
    [ZQTools pushNextViewController:self.viewController andRootController:law];
}

-(void)selectWoDeOrList:(UIButton *)btn{
    _is_mine=[NSString stringWithFormat:@"%ld",btn.tag-1];
    _page=1;
    [_tableArr removeAllObjects];
   
    _xueYuan=[UIButton new];
    [_headView addSubview:_xueYuan];
    [_xueYuan setFrame:CGRectMake(0, 5, _mainW*0.4, 50)];
    [_xueYuan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(_mainW*0.1);
        make.width.mas_equalTo(_mainW*0.4);
        make.height.mas_equalTo(50);
    }];
    
    maskPath = [UIBezierPath bezierPathWithRoundedRect:_xueYuan.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(10, 10)];
    
    maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _xueYuan.bounds;
    maskLayer.path = maskPath.CGPath;
    [_xueYuan.layer addSublayer:maskLayer];
    
    _geShou=[UIButton new];
    [_headView addSubview:_geShou];
    [_geShou setFrame:CGRectMake(0, 0, _mainW*0.4, 50)];
    [_geShou mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_xueYuan);
        make.left.mas_equalTo(_xueYuan.mas_right).mas_equalTo(0);
        make.width.mas_equalTo(_mainW*0.4);
        make.height.mas_equalTo(50);
    }];
    
    maskPath3 = [UIBezierPath bezierPathWithRoundedRect:_geShou.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    maskLayer3 = [[CAShapeLayer alloc] init];
    maskLayer3.frame = _geShou.bounds;
    maskLayer3.path = maskPath3.CGPath;
    [_geShou.layer addSublayer:maskLayer3];
    
    if ([_is_mine isEqualToString:@"0"]){
        maskLayer.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer.fillColor = _backgroundColor.CGColor;
        maskLayer.lineWidth = 1;
        maskLayer.lineJoin = kCALineJoinRound;
        maskLayer.lineCap = kCALineCapRound;
        maskLayer.path = maskPath.CGPath;
        [_xueYuan setTitle:@"我的" forState:UIControlStateNormal];
        [_xueYuan setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        maskLayer3.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer3.fillColor = [UIColor whiteColor].CGColor;
        maskLayer3.lineWidth = 1;
        maskLayer3.lineJoin = kCALineJoinRound;
        maskLayer3.lineCap = kCALineCapRound;
        maskLayer3.path = maskPath3.CGPath;
        [_geShou setTitle:@"听过的" forState:UIControlStateNormal];
        [_geShou setTitleColor:ColorWithRGB(149, 149, 149) forState:UIControlStateNormal];
    }
    else{
        maskLayer.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer.fillColor = [UIColor whiteColor].CGColor;
        maskLayer.lineWidth = 1;
        maskLayer.lineJoin = kCALineJoinRound;
        maskLayer.lineCap = kCALineCapRound;
        maskLayer.path = maskPath.CGPath;
        [_xueYuan setTitle:@"我的" forState:UIControlStateNormal];
        [_xueYuan setTitleColor:ColorWithRGB(149, 149, 149) forState:UIControlStateNormal];
        
        maskLayer3.strokeColor = [UIColor whiteColor].CGColor;
        maskLayer3.fillColor = _backgroundColor.CGColor;
        maskLayer3.lineWidth = 1;
        maskLayer3.lineJoin = kCALineJoinRound;
        maskLayer3.lineCap = kCALineCapRound;
        maskLayer3.path = maskPath3.CGPath;
        [_geShou setTitle:@"听过的" forState:UIControlStateNormal];
        [_geShou setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    _xueYuan.tag=1;
    [_xueYuan addTarget:self action:@selector(selectWoDeOrList:) forControlEvents:UIControlEventTouchUpInside];
    _geShou.tag=2;
    [_geShou addTarget:self action:@selector(selectWoDeOrList:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self loadData];
    [_tableView reloadData];
}
-(void)loadData{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    NSString *token=[userDic objectForKey:@"token"];
    NSNumber *waiter_id1=[userDic objectForKey:@"user_id"];
    NSString *user_id=[NSString stringWithFormat:@"%@",waiter_id1];
      NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:user_id,@"user_id",_is_mine,@"is_mine",[NSString stringWithFormat:@"%d",_page],@"page",@"5",@"pagesize",token,@"token",@"0",@"user_role", nil];
    [ZQTools AFNPostDataUrl:@"user/consult/consult_list" Dict:dic andTableView:nil andViewController:self.viewController andSuccessBlock:^(id responseObject) {
        
        [_tableView.mj_footer endRefreshing];
        [_tableView.mj_header endRefreshing];

        NSArray *typeArr=responseObject;
        [_tableArr addObjectsFromArray:typeArr];
        [_tableView reloadData];
        if (typeArr.count!=0) {
            _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                _page+=1;
                [self loadData];
            }];
        }
        else{
            _tableView.mj_footer.hidden=YES;
        }
        
    } anderrorBlock:nil];
    
}


@end
